package com.doge.controller.admin;

import com.doge.bean.base.BaseParam;
import com.doge.bean.base.BaseRespVo;
import com.doge.bean.bo.keyword.KeywordCreateBO;
import com.doge.bean.pojo.keyword.Keyword;
import com.doge.bean.vo.keyword.KeywordCreateVO;
import com.doge.bean.vo.keyword.ListKeywordVO;
import com.doge.service.admin.keyword.KeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @ClassName: KeywordController
 * @Description: 关键词模块
 * @author: PuJing
 * @create: 2021-11-30-17:47
 **/
@RestController
@RequestMapping("admin/keyword")
public class KeywordController {

    @Autowired
    KeywordService keywordService;


    /**
     * 查询指定条件的关键词信息
     * http://182.92.235.201:8083/admin/keyword/list?
     * page=1&limit=20&  keyword=&url=  &sort=add_time&order=desc
     *
     * @param param
     * @param keyword 关键字
     * @param url 跳转链接
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(BaseParam param,String keyword,String url){

        //是null或"xxx"或""
        ListKeywordVO listKeywordVO = keywordService.list(param,keyword,url);

        return BaseRespVo.ok(listKeywordVO);
    }

    /**
     * 新增关键词
     * @param keywordCreateBO 接收要新增的关键词
     * @return
     */
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody KeywordCreateBO keywordCreateBO){

        KeywordCreateVO keywordCreateVO = keywordService.create(keywordCreateBO);

        return BaseRespVo.ok(keywordCreateVO);
    }


    /**
     * 修改关键词
     * @param keyword 接收要修改的关键词
     * @return
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Keyword keyword){

        Keyword keywordUpdate = keywordService.update(keyword);

        return BaseRespVo.ok(keywordUpdate);
    }

    /**
     * 删除关键字
     * @param keywordCreateVO 接收要删除的关键字
     * @return
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody KeywordCreateVO keywordCreateVO){

        int code = keywordService.delete(keywordCreateVO);

        if (code == 200) {
            return BaseRespVo.ok();
        } else {
            return BaseRespVo.error(621, "删除关键字失败");
        }
    }

}
